{extend name="base"/}
{block name="resources"}
<style  type="text/css">
    .form-group{
        width: 100%;
    }
</style>
{/block}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="javascript:;" class="n_tab_list">添加配送规则</a>
        </div>
        <div class="panel mb-3" id="app">
            <div class="panel-body">
                <form class="auto-form" method="post" id="form">
                    <input type="hidden" value="{$pid}" name="pid">
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                            <label class="col-form-label required">配送名称</label>
                        </div>
                        <div class="col-sm-6">
                            <input class="form-control" name="name" value="{$model['name']}">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                            <label class="col-form-label">配送平台</label>
                        </div>
                        <div class="col-sm-6">
                            <select class="form-control" name="delivery_type" v-model="delivery_type">
                                {volist name="type" id='vo' key="k"}
                                <option value="{$k}">{$vo}</option>
                                {/volist}
                            </select>
                            <div class="text-muted fs-sm">目前支持达达、UU、快跑者及商家配送</div>
                        </div>
                    </div>
                    <div v-if="delivery_type == '1'">
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">商家编号(source_id)</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="delivery_setting[name]"
                                       value="{$model['delivery_setting']['name']}">
                            </div>
                            <div class="text-muted fs-sm"> 商家编号 (创建商家账号分配的商家编号)</div>
                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">app_key</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="delivery_setting[key]"
                                       value="{$model['delivery_setting']['key']}">
                            </div>
                            <div class="text-muted fs-sm"> 登录开发者账号:账号管理-》开发助手-》应用信息 处获取app_key</div>

                        </div>
                        <div class="form-group row">
                            <div class="form-group-label col-sm-2 text-right">
                                <label class="col-form-label">app_secret</label>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" name="delivery_setting[secret]"
                                       value="{$model['delivery_setting']['secret']}">
                            </div>
                            <div class="text-muted fs-sm"> 登录开发者账号:账号管理-》开发助手-》应用信息 处获取app_secret</div>
                        </div>
                        <div>在测试环境，使用统一商户和门店进行发单。其中，商户id：73753，门店编号：11047059
                            前往申请<a href="http://newopen.imdada.cn" target="_blank">http://newopen.imdada.cn</a>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="form-group-label col-sm-2 text-right">
                        </div>
                        <div class="col-sm-6">
                            <button type="submit" class="btn btn-primary auto-form-btn" href="javascript:">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </article>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                delivery_type:'{$model.delivery_type|default=1}'
            }
        });
        var flag = false;
        $("#form").on("submit",function () {
            if(flag){return};
            flag = true;
            $.ajax({
                url: "{:url('delivery/edit')}",
                type: 'POST',
                cache: false,
                data: new FormData($('#form')[0]),
                processData: false,
                contentType: false,
                dataType: 'json',
                success:function (res) {
                    console.log(res);
                    flag = false;
                    if(res.code == 1)
                    {
                        layer.msg(res.message,{icon:1,time:1000},function () {
                            window.location.href = "{:url('delivery/index')}";
                        });
                    }
                    else
                    {
                        layer.msg(res.message,{icon:5,time:1000});
                    }
                },
                error:function (err) {
                    console.log(err);
                    flag = false;
                }
            }).done(function(res) {
            }).fail(function(res) {
            });
            return false;
        });
    </script>
</div>
{/block}